using System;
using System.Xml;

namespace XNASpriteLib
{
	class Animation
	{
		private readonly String name;
		private readonly double fps;
		private readonly String nextAnimationName;

		public Animation(String name, double fps)
		{
			this.name = name;
			this.fps = fps;
			nextAnimationName = null;
		}


		public Animation(XmlNode node, double defaultFPS)
		{
			if (node == null)
			{
				throw new ArgumentNullException("node", "Animation could not be loaded because the XML node was null");
			}
			else if (node.Attributes == null)
			{
				throw new ArgumentException("Animation could not be loaded because the XML node's Attributes are null");
			}


			if (node.Attributes["name"] != null)
			{
				name = node.Attributes["name"].Value;
			}
			else
			{
				throw new ArgumentException("Animation could not be loaded because the animation does not have a name");
			}



			if (node.Attributes["fps"] != null)
			{
				String tmp = node.Attributes["fps"].Value;
				if (!double.TryParse(tmp, out fps))
				{
					fps = defaultFPS;
				}
			}
			else
			{
				fps = defaultFPS;
			}


			// TODO: Load Next Animation list
			nextAnimationName = Name;
		}

		public String Name
		{
			get { return name; }
		}

		public double FPS
		{
			get { return fps; }
		}
		
		public String NextAnimationName
		{
			get{ return nextAnimationName; }
		}
	}
}
